package com.chen.apidriver.controller;

import com.chen.apidriver.service.VerificationCodeService;
import com.chen.internalcommon.dto.ResponseResult;
import com.chen.internalcommon.request.VerificationCodeRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenLiuPing
 **/
@RestController
@Slf4j
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 获取验证码
     * @param verificationCodeRequest
     * @return
     */
    @GetMapping("/verification-code")
    public ResponseResult verificationCode(@RequestBody VerificationCodeRequest verificationCodeRequest) {
        String driverPhone = verificationCodeRequest.getDriverPhone();
        log.info("driverPhone:{}", driverPhone);
        return verificationCodeService.checkAndSendVerificationCode(driverPhone);
    }

    /**
     * 校验验证码
     * @param verificationCodeRequest
     * @return
     */
    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@RequestBody VerificationCodeRequest verificationCodeRequest) {
        String verificationCode = verificationCodeRequest.getVerificationCode();
        String driverPhone = verificationCodeRequest.getDriverPhone();
        log.info("司机电话号码：{}", driverPhone);
        log.info("验证码：{}", verificationCode);
        return verificationCodeService.checkCode(driverPhone, verificationCode);
    }
}
